package br.inf.solutions.apresentacoes.ssp.control.validator;

import java.lang.reflect.Field;
import java.util.Map;

import br.com.vexillum.control.manager.ExceptionManager;
import br.com.vexillum.control.validator.Validator;
import br.com.vexillum.model.ICommonEntity;
import br.com.vexillum.util.ReflectionUtils;
import br.com.vexillum.util.Return;

public class BaseValidator extends Validator {

	public BaseValidator(Map<String, Object> mapData) {
		super(mapData);
	}
	
	public Return validateSearchByHQL(){
		return validateSearch();
	}
	
	public Return validateSearchByCriteria(){
		return validateSearch();
	}
	
	public Return validateSearch(){
		ICommonEntity person = (ICommonEntity) entity;
		Return ret = creatReturn(null, getValidationMessage(null, "searchbycriteria", false));
		try {
			Map<Field, Object> fields = ReflectionUtils.getSearchFieldsAndValues(person, true);
			for (Field field : fields.keySet()) {
				Object value = fields.get(field);
				if(!field.getName().equals("active") && value != null && !value.toString().equals("")){
					return new Return(true);
				}
			}
		} catch (Exception e) {
			ret = new ExceptionManager(e).treatException();
		}
		return ret;
	}
	

}
